package com.creatapark.util;

import java.util.Random;

/**
 * PlateNumberGenerator
 *
 * @author Bruce01.fan
 * @date 2017/12/20
 */
public class PlateNumberGenerator {

    private static final String[] provinces = new String[]{"粤","京","津","沪","渝","冀"};


    public static String generate(){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(getProvince());
        stringBuffer.append(genAlphabe(1)).append(" ").append(genAlphabe(1));
        stringBuffer.append(genNumber(2)).append(genAlphabe(1)).append(genNumber(1));
        return stringBuffer.toString();
    }

    private static String getProvince() {
        Random random = new Random();
        int index = random.nextInt(provinces.length-1);
        return provinces[index];
    }

    private static String genAlphabe(int num) {
        StringBuffer stringBuffer = new StringBuffer();

        for(int i=0;i<num ;i++) {

            long letter = (long) (65+(90-65)* (Math.random()));

            stringBuffer.append((char)letter);
        }

        return stringBuffer.toString();
    }

    private static String genNumber(int num) {
        StringBuffer stringBuffer = new StringBuffer();

        for(int i=0;i<num ;i++) {

            long letter = (long) (10* (Math.random()));

            stringBuffer.append(letter);
        }

        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        System.out.println(PlateNumberGenerator.generate());

    }

}
